package anagram;

public class Main {

	public static void main(String[] args) {
		Main anagram = new Main();
		anagram.begin();
	}
	
	
	public void begin(){
		String palavra = new String("aabc");
		
		//palavra.charAt(0);		
//		for(int i = 0; i < palavra.length(); i++){			
//			palavra.subSequence(i, palavra.length());		
//		}
		
        //char[] test = {'a','b','c','d'}; //create our string
        permute(palavra.toCharArray(), 0, 4); //call it
		
	}
	
//	public String[] permuta(String permutar){	
//		
//	}
	
    public static void swap(char[] set, int first, int second) //troca
    {
        char ch = set[second]; //so we pass the char array and assign, since this will hold
        set[second] = set[first]; //swap the values
        set[first] = ch;
    }
    
    public static int permute(char[] set, int begin, int end)
    {
        int i;
        int range = end - begin;
        if (range == 1) {
                  System.out.println(set);
        } else {
                  for(i=0; i<range; i++) {
                            swap(set, begin, begin+i);              //initial swap
                            permute(set, begin+1, end);             //recursion
                            swap(set, begin, begin+i);         //swap back
                          }
                }
        return 0;
    }
	
}



//public class Permute {      
//
//
//}

